package com.dooboolab.fluttersound;

import com.dooboolab.TauEngine.Flauto.t_LOG_LEVEL;

import java.util.HashMap;
import java.util.Map;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;


public abstract class FlutterSoundSession {
    int slotNo;

    void init(int slot) {
        slotNo = slot;
    }

    abstract FlutterSoundManager getPlugin();

    void releaseSession() {
        getPlugin().freeSlot(slotNo);
    }

    abstract int getStatus();

    abstract void reset(final MethodCall call, final MethodChannel.Result result);

    void invokeMethodWithString(String methodName, boolean success, String arg) {
        Map<String, Object> dic = new HashMap<String, Object>();
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("arg", arg);
        dic.put("success", success);
        getPlugin().invokeMethod(methodName, dic);
    }

    void invokeMethodWithDouble(String methodName, boolean success, double arg) {
        Map<String, Object> dic = new HashMap<String, Object>();
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("arg", arg);
        dic.put("success", success);
        getPlugin().invokeMethod(methodName, dic);
    }


    void invokeMethodWithInteger(String methodName, boolean success, int arg) {
        Map<String, Object> dic = new HashMap<String, Object>();
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("arg", arg);
        dic.put("success", success);
        getPlugin().invokeMethod(methodName, dic);
    }


    void invokeMethodWithBoolean(String methodName, boolean success, boolean arg) {
        Map<String, Object> dic = new HashMap<String, Object>();
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("arg", arg);
        dic.put("success", success);
        getPlugin().invokeMethod(methodName, dic);
    }

    void invokeMethodWithMap(String methodName, boolean success, Map<String, Object> dic) {
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("success", success);
        getPlugin().invokeMethod(methodName, dic);
    }

    public void log(t_LOG_LEVEL level, String msg) {
        Map<String, Object> dic = new HashMap<String, Object>();
        dic.put("slotNo", slotNo);
        dic.put("state", getStatus());
        dic.put("level", level.ordinal());
        dic.put("msg", msg);
        dic.put("success", true);
        getPlugin().invokeMethod("log", dic);

    }

}
